import {ApiResult} from '@/phr/common/ApiResult';
import {Medicine} from '@/phr/service/medicine/Medicine';
import HttpClient from '@/phr/common/HttpClient';
import {PageDTO} from '@/phr/common/PageDTO';

/**
 * 药品相关服务接口
 */
class MedicineService {

  private SEARCH_MEDICINE_URL = 'medicine/api/search';
  private GET_MEDICINE_DETAIL_URL = 'medicine/api/detail';

  /**
   * 查找药品
   * @param {string} name 药品名称
   * @param {number} page 当前页数，默认为第一页，一页数据为10项
   * @returns {Promise<ApiResult<Medicine[]>>} 返回药品列表
   */
  public async searchMedicine(name: string, page: number = 1): Promise<ApiResult<PageDTO<Medicine>>> {
    let params = {
      name: name,
      page: page
    };
    return HttpClient.get(this.SEARCH_MEDICINE_URL, params);
  }

  /**
   * 获取药品详情
   * @param {number} id 药品ID
   * @returns {Promise<ApiResult<Medicine>>} 药品对象
   */
  public async getMedicineDetail(id: number): Promise<ApiResult<Medicine>> {
    let params = {
      id: id
    };
    return HttpClient.get(this.GET_MEDICINE_DETAIL_URL, params);
  }

}

export default new MedicineService();